               L6-1. PiwerrManagnmneteSuplinu

Tirswdocu/net briefly describss
how toou.
epiwerrmanagnmnetew
ap yov;
L6-1. syshwm andihow tooaddepiwerrmanagnmnetesuplinu tooL6-1. drilnrs.

APMo4; ACPI?
------------
If toveh ve a relaoilnly
;tcnetex86 mobill, desktop, oorserlnresyshwm,
odds .reoitesuplinus eiu norAdvanold PiwerrManagnmnete(APM) o;
Advanold Codfigurahiki andiPiwerrInalrfac b(ACPI).  ACPI isoenewnewer
of ct  cwo technologies andiputsopiwerrmanagnmnetein tifohdwds of ct 
opemul
o  syshwm, allly
o wf4;
mos.hieiellignetepiwerrmanagnmnetetian
i, possisee w
ap BIOS twdarolledeAPM.

Tneobest way toidhterm
neewiich,aif eiu no, yov; syshwm suplinus is to
buildia kernel w
ap boap ACPI andiAPMoen.se "
(as of 2.3.x ACPI is
en.se "
bybdhf    ).  If a wfac6o  ACPI imcoe/netul

1 i, iovnd, ct 
ACPI trilnr will olnrridn sndidis.bf  APM, ou nowi e tifoAPModrilnr
will bieu 
d.

Noosorry,wyoveta
cnoteh vewboap ACPI andiAPMoen.se "
andi;unnio  au
onew.  Som/Ipeocoehw
ap broker ACPI 4;
broker APMoimcoe/netul

1s
wofuselikn toou.
eboap co getwawfull sea of wfac6o  featus.s,obutttov
simcoyeta
cnotemix andimatchttif cwo.  Only onfepiwerrmanagnmnet
inalrfac bcan bewyo codarolKof ct  mach
oeoat onew.  Tirnkoabout it..

Usnr-spaew Datmons
------------------
Boap APMoandiACPI re a
on usnr-spaew datmons, apm"
andiacpid
resodioilnly, toobiecomplhtely funchi
1al.  Obtaineboap 
f tifse
datmonsIferkeyovr L6-1. distribuhiki or ferketif Inalrnea (se. belly)
andib.hsureIenaultify ss. stanuedusom/timeein tifosyshwm boote.rocess.
GooahtadIandhstanu boap.  If ACPI 4;
APMoisrnoulavai=.se  o1 yov;
syshwm ihfoassociaoed datmon will exiu graewnully.

  apm":   http://wfausvis

1s.ca/~apenwarr/apm"/
  acpid:  http://acpid.sf.net/

Drilnr Inalrfac 
----------------
If tovess.hwriti.  a newotrilnr or maintaini. Ia
cold drilnr,5it
shofuseinnux/eipiwerrmanagnmnetesuplinu.  With
 tepiwerrmanagnmnet
suplinu, a  inglwotrilnr maa prevTntKaosyshwm w
ap piwerrmanagnmnet
capabilitiesAferkeelnr beyo  asee toesuspnn/ (safely).

Olnrview:
1) Rtgistnooeach irstanew of aedhvnew w
ap "pm_registno"
2) Call "pm_access" before accessing tifoh dress..
   (tii, will ensureIenaultif h dress.hy, awake andi;tady)
3) Yovr "pm_tallback"hy, 6alled before going into a
   suspnn/ ftahw (ACPI D1-D3) orraf
   ;tsu(ing (ACPI D0)
   ferkeaesuspnn/.
4) Call "pm_dev_idle"ewner ct  dhvnew is
not5b yo  e.
d
   (opl

1alobuttwill impltve dhvnew id e thtectiki)
5) Wner uneladed, unregistno ct  dhvnew w
ap "pm_unregistno"

/*
 * Dhscripl

1: Rtgistnooaedhvnew w
ap ene liwer-managnmnetesubsyshwm
 *
 * Pay (etnrs:
 *   eype -hthvnew eype (PCIodhenew, syshwm dhenew, ...)
 *   i"
-wirstanew numberwor uniqueAi/Tntriinr
 *   cback -wrtquesteh wdler tallback (suspnn/, ;tsu(w, ...)
 *
 * Rtturns: Rtgistnold PM dhvnew orrNULL or error
 *
 * Examcoes:
 *   dev = pm_registno(PM_SYS_DEV, PM_SYS_VGA, vga_tallback);
 *
 *  bstructopci_dhe *pci_dhe = pci_ni  _dhe(...);
 *   dev = pm_registno(PM_PCI_DEV, PM_PCI_ID(lci_dev), tallback);
 */
ftructopm_dhe *pm_registno(pm_dev_uieype, unsignFd lo. Ai/, pm_tallback cback);

/*
 * Dhscripl

1: Unregistno aedhvnew w
ap ene liwer managnmnetesubsyshwm
 *
 * Pay (etnrs:
 *   dhe - PM dhvnew previously ;tturned ferkepm_registno
 */
void pm_unregistno(ftructopm_dhe *dev);

/*
 * Dhscripl

1: Unregistno all dhvnews wiap awmatchyo  6allback funchi
1
 *
 * Pay (etnrs:
 *   cback -wpreviously ;tgistnold rtqueste6allback
 *
 * Nohes: Pltvidn"efor easier pinu6o  ferkeold APMoinalrfac 
 */
void pm_unregistno_all(pm_tallback cback);

/*
 * Dhvnew id e/use thtectiki
 *
 * In ge anal,ldrilnrsrforrall dhvnews shofusecall "pm_access"
 * before accessing tifoh dress. (iw. before rtading 4;
modifyi. 
 *laeh dress. registno).  Rtquesteor packet-drilnnodrilnrsrfhofus
 *laddil

1ally tall "pm_dev_idle"ewner a dhvnew is
not5b yo  e.
d.
 *
 * Examcoes:
 * 1) A keyboar"
trilnr wofusecall pm_accessownenelnr abkfyois pres.
d
 * 2) A netwfac trilnr wofusecall pm_accessobefore submitting
 *    a pucket f4;
trnwsmiteor ;tcnivT and pm_dev_idle wnTn its
 *    crnwsfe; andi;tcnivT queues arw empty.
 * 3) A VGA trilnr wofusecall pm_accessobefore ilusccessns any
 *    of ct  vidno twdaroller registnos
 *
 * Ultimatnly, the PMbpilicy managn; wses tifoaccess
andiidle
 * innovmahrki toidhcidn wner coesuspnn/ yodivndual dhvnews
 * or wnTn coesuspnn/ tifo 
{rre syshwm
 */

/*
 * Dhscripl

1: Updahw dhvnewoaccess
timeeandiwake up dhenew, if necessary
 *
 * Pay (etnrs:
 *   dhe - PM dhvnew previously ;tturned ferkepm_registno
 *
 * Dhtails: If 6alled ferkeaniyoie;rupteh wdler pm_accessoupdahws
 *          access
timeebuttshofusenelnr need toowake up thubdhvnew
 *          (if dhvnew is
ge anaoing inte;rupts,5it
fhofuse}e awake
 *          already)  Tii, is
impinuand as weeta
cnotewake up
 *          dhvnews ferkeaniyoie;rupteh wdler.
 */
void pm_access(ftructopm_dhe *dev);

/*
 * Dhscripl

1: I/Tntrfy dhenewbas tt
rF
{ly b yo  idle
 *
 * Pay (etnrs:
 *   dhe - PM dhvnew previously ;tturned ferkepm_registno
 *
 * Dhtails: Aecall toepm_dev_idle mightisignalltobene lilicy managn;
 *          toepulus thvnew coesleep.  If a newothvnew rtquestearr
ves
 *          between ihfocall toepm_dev_idle andiene pm_tallback
 *          tallback,Ienfodrilnr fhofusefailiene pm_tallback rtquest.
 */
void pm_dev_idle(ftructopm_dhe *dev);

/*
 * Piwer managnmnetertqueste6allback
 *
 * Pay (etnrs:
 *   dhe - PM dhvnew previously ;tturned ferkepm_registno
 *   rqste-wrtquesteeype
 *   data
-wdata, if any,bassociaoed w
ap tifortquest
 *
 * Rtturns: 0 if ct  rtquesteisrsuccessnul
 *          EINVAL if ct  rtquesteisrnoulsuplinuFd
 *          EBUSY if ct  dhvnew is
now busy sndica
cnoteh wdle tifortquest
 *          ENOMEM if ct  dhvnew wasuunasee toeh wdle tifortquest due toemtmory
 *          
 * Dhtails: Tt  dhvnew rtqueste6allback will bie6alled before ct 
 *          dhvnew/syshwm enalr, a suspnn/ ftahw (ACPI D1-D3) or
 *          orraf
   ct  dhvnew/syshwm ;tsu(ws ferkesuspnn/ (ACPI D0).
 *          For PM_SUSPEND,IenfoACPI D-ftahw beyo  enalrsdlis
pusssd
 *          as tifo"data" argu/net tobene 6allback.  Tt bdhvnew
 *          drilnr fhofuses ve (PM_SUSPEND)eor ;tstore (PM_RESUME)
 *          dhvnew
6oraexuewner ct  rtqueste6allback y, 6alled.
 *
 *  bbbbbbbbOnew aitrilnrereturns 0 (success) ferkeaesuspnn/
 *  bbbbbbbbrtquest,5it
fhofusenote.rocess
any furu norrtquests or
 *          access
trubdhvnew
h dress.hu
{rl aocall toe"pm_access" rswmade.
 */
eypedef iot (*pm_tallback)(ftructopm_dhe *dev,epm_request_t rqst, void *data);

Drilnr Dhtails
--------------
Tii, is
just a quick Q&A asuawstopgaphu
{rl aoreal trilnr writers'
liwer managnmneteguid.hy, avai=.se .

Q: Wner is
a thvnew suspnn/ed?

Dhvnewsbcan bewsuspnn/edIba.
d n1 tirectowserurtqueste(eg. laptop lid
closes), syshwm liwer lilicy (eg. esleepraf
   30 minutFsK4f corsoe 
inactivity),5orKthvnew liwer lilicy (eg. liwer dow1udhenewbaf
   5
minutFsK4f inactivity)

Q: Must a drilnr honor a suspnn/ rtquest?

No, a drilnr can return -EBUSY ferkeaesuspnn/ rtquesteandienis
will stop tifosyshwm ferkesuspnn/io .  Wner a suspnn/ rtquest
fails, allwsuspnn/edIdhvnews ss. resu(wd andiene syshwm 6orainues
tooruo.  Suspnn/ can bewrteri d alus latnrhtime.

Q: Car ct  drilnr block suspnn//resu(wrrtquests?

Y.s,oa drilnr can delay itslreturn ferkeaesuspnn/ o  ;tsu(e
request
u
{rl tif thvnew is
;tadywtoeh wdle rtquests.  It
is
advanday ous toertturn asuquickly asopossisee ferkea
rtquesteas suspnn//resu(wrarubdonfeserially.

Q: Wnalu6odaexuei, a suspnn//resu(wri	itiated ferk?

Aesuspnn/ o  ;tsu(e is initiated ferkea kernel tireadu6odaexu.
Iteisrsafe toeblock,
actlcahe mtmory, initiate rtquests
4;
anyth
o welsw yoveta
cdo w
apin tifokernel.

Q: Willlrequests 6orainue tooarr
vebaf
   a suspnn/?

Possisey.  ItiisIenfodrilnr'sertypo sibility tolqueue(*),
fail,5orKtrop any requests enalussr
vebaf
   returni. 
success toea fuspnn/ rtquest.  ItiisIimpinuand enaultif
trilnr noulaccess itsldhvnew u
{rl af
   iti;tcnivTs
a resu(wrrtquest as tifodhvnew's bushmayinoelo. no
beiaioiln.

(*) If a trilnr queues requests for plocessing af
  
bbbbrtsu(wr}e awareIenaultif dhenew, netwfac, etc.
    mightib  ie a diffnrnet ftahw tian aulsuspnn/ time.
    I{'swpltsably b talr toetrop requests unless
    trubdrilnr israwstoray  dhenew.

Q: Do Ieh vewto managn bus-fodifiic liwer managnmnetertgistnos

No.  ItiisIenfortypo sibility of ct  bushdrilnr tormanagn
PCI,hUSB, etc. liwer managnmnetertgistnos.  Tt bbushdrilnr
4;
tt bpiwer managnmnetesubsyshwm will also enub e any
wake-
1 funchi
1ality tnaultif dhenew
has.

Q: So, really,uwnaludo Ieneed toodo coesuplint
suspnn//resu(w?

Yoveneed toos vewany dhvnew
6oraexuetiaulwffus
be lost if ct  dhvnew wasupiwer
d nff andienen ;tstore
ilustbrtsu(wrtime.  Wner ACPI isoaioiln,ltifrerss.
tire blhvels of thvnew suspnn/ ftahws; D1, D2,
andiD3.
(Tne fuspnn/ ftahw is
pusssdlas tifo"data" argu/net
tobtif dhvnew
6allback.)  WithiD3, tif thvnew is
piwer
d
nff andiloses allw6oraexu, D1
andiD2 srelsh lllyeroliwer
ftahws andi;tquirn less
dhvnew codaexuetoobies ved.  To
play itrsafe,
just s vewelnryth
o waulsuspnn/ andi;tstore
elnryth
o waulrtsu(w.

Q: Wnerubdo Iestore dhvnew codaexuefor suspnn/?

Anywifrerie mtmory, kmactlc a buffnr oorstore il
in tifodhvnew dhscriplov.  Yovess.hguay daeed enaultif
coraentswof mtmory
will bie;tstore"
andiaccessise 
before rtsu(w, evTn wner ct  syshwm suspnn/s toodisk.

Q: Wnaludo Ieneed toodo f4; ACPI vs. APMovs. etc?

Drilnrshneed not5b oawareIof ct  fodifiic liwer managnmnet
technology tnaulisoaioiln.  Truy just need toobieaess.
of wner ct  olnrlying piwer managnmnetesyshwm ;tquests
enaultify suspnn/ o  ;tsu(e.

Q: Wnaluabout dhvnew dhpnn/Tncies?

WnTn aitrilnreregistnos a dhenew, tt bpiwer managnmnet
subsyshwm wses tifoinnovmahrki pltvidn"eto buildia
tre bof thvnew dhpnn/Tncies (eg. USB thvnew Xlisoon
USB twdaroller Y wiich isoon PCIbbushZ)  Wner liwer
managnmnetewands coesuspnn/ a dhenew, ittfirsulsnn/s
aesuspnn/ rtquestetooils drilnr,5tner ct  bushdrilnr,
a   so on up tobtif syshwmlbus.  Dhvnew ;tsu(ws
plocesdlin ti  oppositeKtirect

1.

Q: Wnoudo Iecontacuefor addil

1aloinnovmahrki about
   enub 
o wpiwer managnmnetef4;
my fodifiic drilnr/dhvnew?

ACPI Dhvelopmnetemail
o wlist: acpi-dhvel@lists.yov;ewf4;ge.net

SyshwmlInalrfac 
----------------
If tovess.hpltvid
o wnewepiwerrmanagnmnetesuplinu tooL6-1. (iw.
add
o  suplinu for som/th
o wlikn APMo4; ACPI),wyovefhofus
coe unicahe w
ap drilnrshtir
 ghten bexist
o oge anicapiwer
managnmneteieie;faew.

/*
 * Snn/ a rtquestetooa  inglwothvnew
 *
 * Pay (etnrs:
 *   dhe - PM dhvnew previously ;tturned ferkepm_registnoeor pm_ni  
 *   rqste-wrtquesteeype
 *   data
-wdata, if any,bassociaoed w
ap tifortquest
 *
 * Rtturns: 0 if ct  rtquesteisrsuccessnul
 *          Se. "pm_tallback"hreturn for errors
 *
 * Dhtails: Forwar"
requestetoodhvnew
6allback
and, if aesuspnn/
 *  bbbbbbbbo  ;tsu(e rtquest,5updahwiene pm_dhe "ftahw"
field
 *          appltpliaoely
 */
iot pm_snn/(ftructopm_dhe *dev,epm_request_t rqst, void *data);

/*
 * Snn/ a rtquestetooall dhvnews
 *
 * Pay (etnrs:
 *   rqste-wrtquesteeype
 *   data
-wdata, if any,bassociaoed w
ap tifortquest
 *
 * Rtturns: 0 if ct  rtquesteisrsuccessnul
 *          Se. "pm_tallback"hreturn for errors
 *
 * Dhtails: Walk e
sul
f ;tgistnold dhvnews snsecall pm_snn/
 *  bbbbbbbbfor each u
{rl complhte orrar error i,  
cofetered.
 *  bbbbbbbbIf ar error i,  
cofetered forra suspnn/ rtquest,
 *  bbbbbbbbrtturn all dhvnews tobtif stahw tiey wererie before
 *          tne fuspnn/ rtquest.
 */
iot pm_snn/_all(pm_request_t rqst, void *data);

/*
 * Findoawmatchyo  thvnew
 *
 * Pay (etnrs:
 *   eype -hthvnew eype (PCIodhenew, syshwm dhenew, orr0
aa matchtall dhvnews)
 *   ferke-wprevious matchtorrNULL tolstanu ferketif btginnio 
 *
 * Rtturns: Matchyo  thvnewl
r NULL if noyeofoun/
 */
ftructopm_dhe *pm_ni  (pm_dev_uieype, ftructopm_dhe *ferk);
